package snakesladders.visual;

import java.awt.event.MouseEvent;

import minidraw.boardgame.BoardDrawing;
import minidraw.framework.DrawingEditor;
import minidraw.standard.MiniDrawApplication;
import minidraw.standard.NullTool;
import snakesladders.domain.Game;
import snakesladders.domain.GameImpl;
import snakesladders.domain.Square;
import snakesladers.view.SnakesAndLaddersFactory;


public class ShowDomainUpdate {

	public static void main(String[] args) {

		Game game = new GameImpl();

		DrawingEditor editor = new MiniDrawApplication("Move a token ...", new SnakesAndLaddersFactory(game) );

		editor.open();

		editor.setTool(new DomainUpdateTool(game));
		BoardDrawing<Square> drawing = (BoardDrawing<Square>) editor.drawing();
		game.addObserver(drawing);
	}
}

class DomainUpdateTool extends NullTool {
	private Game game;
	int clickCount = 0;

	public DomainUpdateTool(Game game) {this.game = game;}
	public void mouseDown(MouseEvent e, int x, int y) {
		switch (clickCount) {
		case 0: game.move(0, new Square(1), new Square(3)); break;
		case 1: game.move(0, new Square(3), new Square(18)); break;
		default:game.rollDie();
		}
		clickCount++;
	}
}






